{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "view-in-github",
    "colab_type": "text"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/ak9250/impersonator/blob/master/impersonator.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "8VEE2lbHAaU6",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!git clone https://github.com/svip-lab/impersonator.git"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "iqJFV169A8yU",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd impersonator/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "Q5bzxmCIBEZR",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "0hITOMy0BIEg",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd thirdparty/neural_renderer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "v7YtWs_BB_oj",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!python setup.py install"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "L2Zk_k5zQBAz",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd ../.."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "BsrST13RCBrJ",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!wget -O assets/pretrains.zip https://1drv.ws/u/s!AjjUqiJZsj8whLNw4QyntCMsDKQjSg?e=L77Elv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "QY66SAXqvgTC",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "VfInCx-lviCl",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!unzip pretrains.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "4qd5Dx7Nvoo8",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd .."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "L15STTOqq4Uw",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!wget -O outputs/checkpoints.zip https://1drv.ws/u/s!AjjUqiJZsj8whLNyoEh67Uu0LlxquA?e=dkOnhQ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "DX-MPQKSs4pA",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "Qz6mYZUEwF1d",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!unzip checkpoints.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "Zm_daNeKwfqQ",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd .."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "Waf-VocmwHlT",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!wget -O assets/samples.zip https://1drv.ws/u/s!AjjUqiJZsj8whLNz4BqnSgqrVwAXoQ?e=bC86db"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "o4T4aonowc4h",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "uVaYlUjBwnx1",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!unzip samples.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "ZsG341nMwpqD",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "cd .."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "UzEEAV_7w3xZ",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "python run_imitator.py --gpu_ids 0 --model imitator --output_dir ./outputs/results/  \\\n",
    "    --src_path      ./assets/src_imgs/internet/men1_256.jpg    \\\n",
    "    --tgt_path      ./assets/samples/refs/iPER/024_8_2    \\\n",
    "    --bg_ks 7   --ft_ks 3 \\\n",
    "    --has_detector  --post_tune --front_warp \\\n",
    "    --save_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "dCrFpImFss1p",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "python run_swap.py --gpu_ids 0 --model imitator --output_dir ./outputs/results/  \\\n",
    "    --src_path      ./assets/src_imgs/imper_A_Pose/024_8_2_0000.jpg    \\\n",
    "    --tgt_path      ./assets/src_imgs/fashion_man/Sweatshirts_Hoodies-id_0000680701_4_full.jpg    \\\n",
    "    --bg_ks 13  --ft_ks 3 \\\n",
    "    --has_detector  --post_tune  --front_warp --swap_part body  \\\n",
    "    --save_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "OEuNWk6Gt3sb",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "python run_view.py --gpu_ids 0 --model viewer --output_dir ./outputs/results/  \\\n",
    "--src_path      ./assets/src_imgs/internet/women1_256.jpg    \\\n",
    "--bg_ks 13  --ft_ks 3 \\\n",
    "--has_detector  --post_tune --front_warp --bg_replace \\\n",
    "--save_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "fjERmHmJ0I4L",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -f image2 -i /content/impersonator/outputs/results/imgs/%*.jpg -c:v libx264 -pix_fmt yuv420p out.mp4 -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "V4J6dde53ZIH",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -f image2 -i /content/impersonator/outputs/results/imitators/gt_%04d.jpg -c:v libx264 -pix_fmt yuv420p out2.mp4 -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "TpNIX-xg6mby",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -f image2 -i /content/impersonator/outputs/results/imitators/pred_%04d.jpg -c:v libx264 -pix_fmt yuv420p out3.mp4 -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "M1rIptSs7sW5",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i out2.mp4 -filter_complex \"[0:v] palettegen\" palette.png -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "miT5Lh-K7ybB",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i out2.mp4 -i palette.png -filter_complex \"[0:v][1:v] paletteuse\" endresult.gif -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "TmySGWrg76Ed",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i out3.mp4 -filter_complex \"[0:v] palettegen\" palette2.png -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "vO4yh4XX8G8X",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i out3.mp4 -i palette2.png -filter_complex \"[0:v][1:v] paletteuse\" endresult2.gif -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "uzBQa8K18LqX",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i endresult.gif -i endresult2.gif -filter_complex hstack outputstack2.gif -y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "id": "GT5o6Dmq8WAw",
    "colab_type": "code",
    "colab": {}
   },
   "outputs": [],
   "source": [
    "!ffmpeg -i outputstack2.gif -f mp4 -c:v libx264 -pix_fmt yuv420p combined.mp4"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "name": "impersonator.ipynb",
   "provenance": [],
   "include_colab_link": true
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "accelerator": "GPU"
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
